<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
</head>
<body>
<img src="img/banner_1.jpg" id = "pic" width="100%">

<script>
    var flag = 1 ;
    function fun(){
        var pic = document.getElementById("pic");
        flag++;
        if(flag>3)
        {
            flag=1;
            //防止flag太大了
        }
        pic.src="img/banner_"+flag+".jpg";
    }
    var id = setInterval(fun,3000);
</script>
</body>
</html>